/*
 * Degree.java
 * Created on March 25, 2007, 11:10 AM
 * @author dwight fellman
 * $Id: Degree.java 172 2007-04-27 18:03:24Z dwight $
 */

package CSIS543TFinalProject;

import java.util.ArrayList;
import java.util.List;

/**
 contains the isValidPlan(), which has logic to verify if a given course plan
 meets the degree requirements.
 */
public class Degree {
   private String Name;
   private String Concentration;
   private int MinCourses;
   private int MinCredits;
   private List <Course> RequiredCourses = new ArrayList <Course> ();
   
   /**
    Pass-in the name of the degree; the concentration; the minimum
    number of credits and the minimum number of courses required to fullfill the
    degree.
    
    required and elective courses are added later.
    */
   public Degree(String name, String concentration, int minCourses, int minCredits) {
      this.Name = name;
      this.Concentration = concentration;
      this.MinCourses = minCourses;
      this.MinCredits = minCredits;
   }
   
   /**
    Create a Degree with only the name and the concentration. for a non-
    concentration degree, leave the concentration blank. this can be used for
    oo-database 'queries'
    */
   public Degree(String name, String concentration) {
      this(name, concentration, 0, 0);
   }
   
   /**
    for the given plan, return TRUE if the plan meets the requirements to
    graduate.
    */
   public boolean isValidPlan(Plan plan) {
      //todo
      return false;
   }
   
   /**
    for the given plan, return the number of courses remaining that need to be
    taken to graduate.
    */
   public int getRemainingCourseCount(Plan plan) {
      //todo
      return 0;
   }
   
   /**
    for the given plan, return the number of credits remaining that need to be
    taken to graduate. a negative number is OK; it just means that too many
    credits are planned..
    */
   public int getRemainingCreditCount(Plan plan) {
      //todo
      return 0;
   }
   
   public String getName() {
      return Name;
   }
   
   public String getConcentration() {
      return Concentration;
   }
   
   public int getMinCourses() {
      return MinCourses;
   }
   
   public int getMinCredits() {
      return MinCredits;
   }
   
   public String toString() {
      String s = String.format("%d %s %s minCourses: %d; minCredits: %d",
         getName(),
         getConcentration(),
         getMinCourses(),
         getMinCredits());
      return s;
      
   }
   
   /**
    used to compare two Degree objects for equality.
    */
   public boolean equals(Object obj) {
      // todo
      Degree d = (Degree) obj;
      boolean b =
         this.Concentration.equals(d.Concentration) &&
         this.MinCourses == d.MinCourses &&
         this.MinCredits == d.MinCredits &&
         this.Name.equals(d.Name) &&
         this.RequiredCourses.equals(d.RequiredCourses);
      return b;
   }
   
   /**
    Degree object need to be loaded with their required courses.
    */
   public void AddRequiredCourse(Course course) {
      if (RequiredCourses.contains(course)) {
         // don't allow duplicates
      } else {
         RequiredCourses.add(course);
      }
   }
   
   /**
    return the list of required courses for this degree.
    todo: make this list read-only...
    */
   public List<Course> getRequiredCourses() {
      return RequiredCourses;
   }
   
   /**
    return TRUE if the given degree name is required for this degree. (this is
    NOT the same as prerequisites.)
    */
   public boolean isCourseRequiredForDegree(String courseName) {
      for (Course c : RequiredCourses) {
         if (c.getName().equals(courseName)) {
            return true;
         }
      }
      return false;
   }
}